/**
 * Created by haocongshun on 2016/10/15.
 */
var contextPath = "";
$(function () {
    contextPath=getContextPath();
    blindBtn();
});
function blindBtn() {
    $(".freezeBtn").unbind("click");
    $(".unfreezeBtn").unbind("click");
    $(".deleteBtn").unbind("click");
    $(".freezeBtn").click(function () {
        freezeUser($(this).attr("data-id"));
    });
    $(".unfreezeBtn").click(function () {
        unfreezeUser($(this).attr("data-id"));
    });
    $(".deleteBtn").click(function () {
        if($(this).parent().parent().children(".content_count").val()>0){
            alert("该用户发布了多篇文章，无法删除！");
            return;
        }
        deleteUser($(this).attr("data-id"));
    });
}
function freezeUser(id) {
    var url = contextPath+"/userManager/freezeUser.press";
    var data = {};
    data.user_id = id;
    $.post(url,data,function (result) {
        if(result.Msg){
            $("button[data-id='"+id+"']").html("解冻");
            $("button[data-id='"+id+"']").removeClass("btn-primary freezeBtn");
            $("button[data-id='"+id+"']").addClass("btn-danger unfreezeBtn");
            $("button[data-id='"+id+"']").parent().parent().children(".status").html("冻结");
            blindBtn();
        }
    },"json");
}
function unfreezeUser(id) {
    var url = contextPath+"/userManager/unfreezeUser.press";
    var data = {};
    data.user_id = id;
    $.post(url,data,function (result) {
        if(result.Msg){
            $("button[data-id='"+id+"']").html("冻结");
            $("button[data-id='"+id+"']").removeClass("btn-danger unfreezeBtn");
            $("button[data-id='"+id+"']").addClass("btn-primary freezeBtn");
            $("button[data-id='"+id+"']").parent().parent().children(".status").html("正常");
        }
        blindBtn();
    },"json");
}
function deleteUser(id) {
    var url = contextPath+"/userManager/deleteUser.press";
    var data = {};
    data.user_id=id;
    $.post(url,data,function (result) {

    },"json");
}